package com.tz.online.book.service.impl;

import java.util.List;

import com.tz.online.book.dao.IBookDao;
import com.tz.online.book.service.IBookService;
import com.tz.online.entity.Book;
import com.tz.online.entity.Pageing;
import com.tz.online.util.BeanFactory;

/**
 * 商品模块业务层实现
 * @author Administrator
 *
 */
public class BookServiceImpl implements IBookService {
	//通过bean工厂，获得数据访问层接口对象
	IBookDao bd = (IBookDao) BeanFactory.getBean("bookDao");
	@Override
	public Book queryBookById(String id) {
		return this.bd.selectBookById(id);
	}
	
	@Override
	public Pageing queryBookByCondition(int now, int size, String cate) {
		Pageing paging = new Pageing();
		List<Book> books = bd.selectBookByCondition(now, size, cate);
		
		paging.setBooks(books);
		paging.setPageNow(now);
		paging.setPageSize(size);
		
		int rowCount = (int) bd.getRowCount(cate);
		paging.setRowCount(rowCount);
		int pageCount = 0;
		
		if (rowCount % size == 0) {
			pageCount = rowCount / size;
		} else {
			pageCount = rowCount / size + 1;
		}
		
		paging.setPageCount(pageCount);
		
		return paging;
	}
	
}
